﻿using B.S.Procurement.Error;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using B.S.Procurement.Write.Api.Application.Command.PurchaseCommand;
using B.S.Procurement.Write.Api.Application.Command.ProcurementCommand;
using B.S.Procurement.Write.Api.Application.Command.PurchaseDetailsCommand;
using B.S.Procurement.Write.Api.Application.Command.VendorModelCommand;
using B.S.Procurement.Write.Api.Application.Command.VendorTypeModelCommand;

namespace B.S.Procurement.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcurementController : ControllerBase
    {
        private readonly IMediator mediator;

        public ProcurementController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加采购信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> CreateProcument(CreateProcurementCommands request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 添加采购类别
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreatePurchase(createProchaseCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 删除采购信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelProcurement(DelProcurementCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 修改采购信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdProcument(UpdProcurementCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 添加采购明细
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreatePurchaseDetails(CreatePurchaseDetailsCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 删除采购明细
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelPurchaseDetails(DelPurchaseDetailsCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 修改采购明细
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdPurchaseDetails(UpdPurchaseDetailsCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }

        

        /// <summary>
        /// 添加供应商类别成功
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateVendorTypeModel(CreateVendorTypeModelCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
